package com.yq.tanhua.ui.recommend

import com.fmt.mvi.learn.gobal.log
import com.yq.tanhua.net.BaseViewModel
import com.yq.tanhua.net.TanHuaApiService
import com.yq.tanhua.net.vo.TodayBest
import kotlinx.coroutines.flow.MutableStateFlow
class RecommendViewModel : BaseViewModel() {


    val todayBestUiState = MutableStateFlow(TodayBestUiState(null))


    fun initData() {
        getRecommendListAndBest()
    }

    private fun getRecommendListAndBest() {
        launch(
            block = {
                val todayBest = TanHuaApiService.getTodayBest().fullData()
                todayBest.log()
                val recommend =
                    TanHuaApiService.getRecommendation(page = 1, pageSize = 30, "woman").fullData()
                recommend.log()
                todayBestUiState.value =
                    todayBestUiState.value.copy(data = todayBest, recomendList = recommend.items)

            },
            error = {
                it.log()
            }
        )

    }

}

data class TodayBestUiState(
    val data: TodayBest? = null,
    val recomendList: List<TodayBest>? = null
)